package pers.wensheng.patterns.behavioral_pattern.interpreter_pattern.entity;

import lombok.AllArgsConstructor;
import pers.wensheng.patterns.behavioral_pattern.interpreter_pattern.Context;

/**
 * 非终结符表达式角色 减法表达式
 */
@AllArgsConstructor
public class Minus extends AbstractExpression {
    private AbstractExpression left;
    private AbstractExpression right;


    /**
     * 计算表达式
     *
     * @param context
     * @return
     */
    @Override
    public int interpret(Context context) {
        return left.interpret(context) - right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " - " + right.toString() + ")";
    }
}
